package com.plan.code;

/**
 * @description: if-else语句优化(卫语句)
 * @author: admin
 * @time: 2022/12/6 21:03
 */
public class IfElse01 {


    public static void main(String[] args) {
        int old = 30;

        String strMajor = "Software Engineering";

        boolean isPassChoose = true;

        boolean isPassInterview = true;

        boolean isPassed = false;


        /*
          多重IF的嵌套
         */
        if (old <= 35) {
            if ("Software Engineering".equals(strMajor) ){
                if (isPassChoose){
                    if(isPassInterview){
                        isPassed = true;
                    }
                }
            }else {
                System.out.println("strMajor is not Software Engineering");
            }
        }else {
            System.out.println("old is not suitable");
        }
        System.out.println(isPassed);


        /**
         * 通过卫语句do-while来解决嵌套IF的复杂性
         * 一般超过三层都可以考虑使用这种方式
         * switch-case是针对单一变量的情况使用
         */
        do {
            if (old > 35) {
                //不符合年龄
                break;
            }
            if (!"Software Engineering".equals(strMajor)){
                //名字不是Software Engineering
                break;
            }
            if (!isPassChoose){
                //面试没有通过
                break;
            }
            if(!isPassInterview){
                break;
            }
            isPassed = true;
        }while(false);

        System.out.println(isPassed);
    }

}
